import org.junit.Test;

import java.util.ArrayList;
import java.util.Collections;
import java.util.Comparator;
import java.util.List;

public class SortTest {


    @Test
    public void testSort(){

        User user1 = new User("jack",20,60);
        User user3 = new User("lee",20,40);

        User user4 = new User("huang",20,50);
        User user2 = new User("brue",15,50);



        List<User> uList = new ArrayList<User>();
        uList.add(user1);
        uList.add(user2);
        uList.add(user3);
        uList.add(user4);


        Collections.sort(uList, new Comparator<User>() {
            @Override
            public int compare(User o1, User o2) {
                int cr = 0;
                if(o1.getAge()<o2.getAge()){
                    cr = -1;
                }else if(o1.getAge() == o2.getAge()){
                    if(o1.getWeight()<o2.getWeight()){
                        cr = -1;
                    }
                }

                return cr;
            }
        });

        uList.forEach(n -> System.out.println(n));
    }
}
